package com.lg.mengbase.testBaseRecyclerAdapter.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.lg.baselibrary.activity.BaseToolbarActivity;
import com.lg.baselibrary.adapter.BaseRecyclerViewHolder;
import com.lg.baselibrary.adapter.BaseViewHolder;
import com.lg.baselibrary.widget.BaseRecyclerView;
import com.lg.mengbase.R;
import com.lg.mengbase.testBaseRecyclerAdapter.adapter.RecyclerViewItemAdapter;
import com.lg.mengbase.entity.ItemData;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by LiGang on 2017/5/27.
 */

public class TestBaseRecyclerAdapterActivity extends BaseToolbarActivity implements BaseRecyclerViewHolder.OnItemClickListener, BaseRecyclerViewHolder.OnItemLongClickListener {
    @BindView(R.id.recyclerView)
    BaseRecyclerView recyclerView;
    private RecyclerViewItemAdapter adapter;
    @Override
    protected int provideContentViewLayout() {
        return R.layout.activity_baserecyclerviewadapter;
    }
    @Override
    protected void initTitle() {
        setToolbarTitle("BaseRecyclerViewAdapter");
        setToolbarRightButton(R.mipmap.me, new OnToolbarButtonClickListener() {
            @Override
            public void onClick() {
                Toast.makeText(TestBaseRecyclerAdapterActivity.this, "右边按钮被点击", Toast.LENGTH_SHORT).show();
            }
        });
    }
    @Override
    protected void initView() {
        ButterKnife.bind(this);

    }

    @Override
    protected void initData() {
        recyclerView.setLinearLayoutManager(LinearLayoutManager.VERTICAL);
//        recyclerView.setGridLayoutManager(2);
//        recyclerView.setStaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        adapter = new RecyclerViewItemAdapter(this);
        View headerView = LayoutInflater.from(this).inflate(R.layout.header,recyclerView,false);
        adapter.addHeaderView(headerView);
        headerView = LayoutInflater.from(this).inflate(R.layout.header,recyclerView,false);
        adapter.addHeaderView(headerView);
        headerView = LayoutInflater.from(this).inflate(R.layout.header,recyclerView,false);
        adapter.addHeaderView(headerView);

        View footerView = LayoutInflater.from(this).inflate(R.layout.footer,recyclerView,false);
        adapter.addFooterView(footerView);
        recyclerView.setAdapter(adapter);
        adapter.setDatas(getDatas());
        adapter.setOnItemClickListener(this);
        adapter.setOnItemLongClickListener(this);
    }
    private int[] imgIds = {R.mipmap.head1,R.mipmap.head2,R.mipmap.head3,R.mipmap.head4
            ,R.mipmap.head5,R.mipmap.head6,R.mipmap.head7,R.mipmap.head8,R.mipmap.head9
            ,R.mipmap.head10,R.mipmap.head11,R.mipmap.head12,R.mipmap.head13,R.mipmap.head14,R.mipmap.head15};
    private List<ItemData> getDatas() {
        List<ItemData> datas = new ArrayList<>();
        for(int i = 0;i < imgIds.length;i++){
            datas.add(new ItemData("头像"+(i+1),imgIds[i]));
        }
        return datas;
    }

    @Override
    public void onItemClick(BaseViewHolder holder, ViewGroup parent, View itemView, int position) {
        ItemData itemData = adapter.getItem(position);
        Toast.makeText(this, itemData.getName(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onItemLongClick(BaseViewHolder holder, ViewGroup parent, View itemView, int position) {
        ItemData itemData = adapter.getItem(position);
        Toast.makeText(this, itemData.getName(), Toast.LENGTH_SHORT).show();
        return true;
    }


}
